<?php

class wordpress_showtime_slideshow {
	var $gid = 0;


	function wp_gallery_st_shortcut($attr, $type) {
		global $post;
		global $wp_version;
		global $stOptions;
		
		$attributes = $attr;
		
		$classid = 'st_'.$this->gid;
		$this->gid++;
		
		if ( $type )
			$slide = 1;
		else
			$slide = 0;
		
		$height = get_option( 'st_height' );
		$width = get_option( 'st_width' );
		$textbgcolor = get_option( 'st_textbg' ) == 'on' ? get_option( 'st_textbgcolor' ) : '';
		$bgcolor = get_option( 'st_bgcolor' );
		$quality = get_option( 'st_quality' );
		$wmode = get_option( 'st_wmode' );
	
		$transition = get_option( 'st_transition' );
		$transitiontime = get_option( 'st_transitiontime' );
		$transitionease = get_option( 'st_easeFunc' ).get_option( 'st_ease' );
		$rotationtime = get_option( 'st_rotatetime' );
		
		$showcontrols = get_option( 'st_showcontrols' );
		$controls = get_option( 'st_showcontrols' ) == 'on' ? get_option( 'st_controls' ) : '0';
		$fullscreen = get_option( 'st_fullscreen' );
		$showtext = get_option( 'st_showtext' );
		
		$showalt = get_option( 'st_showalt' );
		$autoplay = get_option( 'st_autoplay' );
		$shuffle = get_option( 'st_shuffle' );
		$scale = get_option( 'st_scalemode' );
	
		$link = get_option( 'st_link' );
		$target = get_option( 'st_target' );
	
		$reverse = get_option( 'st_reverse' );
		$imgSize=get_option( 'st_imgsize' );
		$imgFullSize=get_option( 'st_imgfullsize' );

		$alternative=get_option( 'st_alternative' );
	

	extract(shortcode_atts(array(
		'id'         		=> $post->ID,
		'width'				=> $width,
		'height'         	=> $height,
		'bgcolor'         	=> $bgcolor,
		'textbgcolor'       => $textbgcolor,
		'quality'         	=> $quality,
		'wmode'         	=> $wmode,
		
		'rotationtime'		=> $rotationtime,
		'transition'		=> $transition,
		'transitiontime'	=> $transitiontime,
		'transitionease'	=> $transitionease,
		'autoplay'			=> $autoplay,
		'showcontrols'		=> $showcontrols,
		'controls'			=> $controls,
		'fullscreen'		=> $fullscreen,
		'showtext'			=> $showtext,
		'showalt'			=> $showalt,
		'shuffle'			=> $shuffle,
		'scale'				=> $scale,
		'link'				=> $link,
		'target'			=> $target,
		
		'reverse'			=> $reverse,
		'source'			=> $imgSize,
		'sourcehd'			=> $imgFullSize,

		'flickr'			=> '',
		'picasa'			=> ''
	), $attr));		

		//$id = intval($id);
		//echo "showc".$showcontrols;
		

		$gallery='';
		
		if ($alternative == 'gallery')
		{
			$alternative = 'false';
			if ( function_exists( 'gallery_shortcode' ) ) {
				$gallery = gallery_shortcode( $attributes );
			}
		}
		else
		{
			$alternative = plugins_url($path = $stOptions->_pluginSubfolderName . '/showtime/swfobject/expressInstall.swf');
			$gallery = '<div style="width:'.$width.'; height:'.$height.';outline:1px solid gray;padding:10px;background-color:white"><h3>This image gallery requires Flash</h3>
	<p>To view this gallery, JavaScript must be enabled, and you need the latest version of the Adobe Flash Player.</p>
	<p><a href="http://adobe.com/go/getflashplayer" target="_blank">Download the free Flash Player now!</a></p></div>';
		}
	
		$attr = "attr=";
		if ( $flickr ) {
			$flickr = $this->encode($flickr);
			$attr .= "flickr^$flickr*";
		}
		else if ( $picasa ) {
			$picasa = $this->encode($picasa);
			$attr .= "picasa^$picasa*";
		}
		else
			$attr .= "id^$id*";
		if ( $reverse=='on' )
			$attr .= "order^reverse*";
		if ( $imgSize )
			$attr .= "source^$imgSize*";
		if ( $imgFullSize )
			$attr .= "sourcehd^$imgFullSize*";
		if ( $link != '' )
			$attr .= "link^$link*";



		
	
		if ( $slide )
			$output = "
			<!-- generated by showtime WP plugin -->
			<script type='text/javascript'>
			
				var flashvars = {
					
				xml 			: '" . plugins_url($path = $stOptions->_pluginSubfolderName . '/showtime/getxml.php') . "?$attr',
				
				width           : '$width',
				height          : '$height',
				classid         : '$classid',

				rotationtime    : '$rotationtime',
				transition      : '$transition',
				transitiontime  : '$transitiontime',
				transitionease  : '$transitionease',
				autoplay        : '$autoplay',
				showcontrols    : '$showcontrols',
				controls        : '$controls',
				textbgcolor     : '$textbgcolor',

				showtext        : '$showtext',
				showalt         : '$showalt',
				shuffle         : '$shuffle',
				scale           : '$scale',
				target          : '$target'			
				
				
				};
				
				var params = {};
				params.allowFullScreen = 'true';
				params.bgcolor = '$bgcolor';		
				params.quality = '$quality';		
				params.wmode = '$wmode';
				//params.base = 'dirname(__FILE__)';
				//params.allowScriptAccess = 'local';
			
				var attributes = {};
				attributes.styleclass = 'showtime';
												
				swfobject.embedSWF ('" . plugins_url($path = $stOptions->_pluginSubfolderName . '/showtime/st16.swf') . "', '" . $classid . "', '$width', '$height', '10.0.0', '$alternative', flashvars, params, attributes);
			</script>
	
					
			<!-- alternative content -->	
			<div id='" . $classid . "'>$gallery</div>
					
			\n";
		else
			$output = "<div class='gallery' id='gallery_" . $this->gid . "'>
							$gallery
						</div>
					\n";
					
		
						
		return $output;
	}

	
	
	function checkOn( $string ) {
		
		if ( $string == "on" || $string == "true" || $string == "yes" ) {
			return "true";
		} else {
			return "false";
		}
		
	}
	
	function addToHeader() {
		global $stOptions;
		wp_enqueue_script( 'swfobject', plugins_url($path = $stOptions->_pluginSubfolderName . '/showtime/swfobject/swfobject.js'), false );
		//wp_enqueue_script( 'flash_resize', plugins_url($path = $stOptions->_pluginSubfolderName . '/include/flash_resize.js'), false );	
	}
	
	function encode($x) {
	    return base64_encode(rawurlencode($x));
	}

	
	function wp_gallery_st_own_shortcut($attr) {
		return $this->wp_gallery_st_shortcut($attr, 1);
	}
	
}

?>